package com.nycreativity.elecreativity.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
import com.baomidou.mybatisplus.extension.plugins.pagination.Page
import com.nycreativity.elecreativity.entity.po.Favorite;
import com.nycreativity.elecreativity.mapper.FavoriteMapper;
import com.nycreativity.elecreativity.service.FavoriteService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nycreativity.elecreativity.entity.param.PageParam
import com.nycreativity.elecreativity.entity.vo.favorite.FavoriteVO
import com.nycreativity.elecreativity.entity.vo.PageDataVO
import com.nycreativity.elecreativity.mapper.vomapper.FavoriteVOMapper
import com.nycreativity.elecreativity.util.PageUtil
import com.nycreativity.elecreativity.util.usersession.UserContext
import org.springframework.stereotype.Service;
import javax.annotation.Resource

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author sxt && ttxxi
 * @since 2021-03-11
 */
@Service
class FavoriteServiceImpl : ServiceImpl<FavoriteMapper, Favorite>(), FavoriteService {

    @Resource
    lateinit var favoriteMapper: FavoriteMapper

    override fun queryFavorites(pageParam: PageParam): PageDataVO<FavoriteVO> {
        return PageUtil.convert(
            favoriteMapper.selectFavoriteByPage(
                Page<Favorite>(pageParam.currentPage.toLong(), pageParam.pageSize.toLong()),
                UserContext.get()?.id
            )
        )
    }

}
